package com.liao.rent.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @Author: ljt
 * @Description: security用户实体类
 * @DateTime: 2024/11/25 下午11:54
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SysUserDetails implements UserDetails {

    private SysUser user;

    private List<String> authorityList;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<SimpleGrantedAuthority> list = authorityList.stream().map(SimpleGrantedAuthority::new).toList();
        return list;

    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getAccount();
    }

    @Override
    public boolean isAccountNonExpired() {
        return user.getAccountNonExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return user.getAccountNonLocked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return user.getAccountNonExpired();
    }

    @Override
    public boolean isEnabled() {
        return user.getEnabled();
    }
}
